#!/bin/bash

# Prompt the user to input VEHICLE_NUM
read -p "Enter the number simulate of vehicles (e.g., 17): " VEHICLE_NUM

# Validate the input to ensure it's a valid number
if ! [[ "$VEHICLE_NUM" =~ ^[0-9]+$ ]]; then
    echo "Invalid input! Please enter a valid number."
    exit 1
fi

# 获取项目目录
PROJECT_DIR=$(cd "$(dirname "$0")" && pwd)
echo "当前脚本所在目录是: $PROJECT_DIR"
ROS_SETUP="/opt/ros/foxy/setup.bash"
OUTPUT_FILE="yijianqifei.sh"


# Create or clear the output file
echo "" > $OUTPUT_FILE

# List of launch files with their extra parameters
declare -A LAUNCH_COMMANDS=(
    ["avoid_node_launch.py"]="vehicle_num:=${VEHICLE_NUM}"
    ["getlocalpos_node_launch.py"]="vehicle_num:=${VEHICLE_NUM}"
    ["communication_multirotor_node_multi_launch.py"]="vehicle_num:=${VEHICLE_NUM} start_node:=0 end_node:=${VEHICLE_NUM}"
)
# Loop over the dictionary and generate the commands
for LAUNCH_FILE in "${!LAUNCH_COMMANDS[@]}"; do
    PARAMS=${LAUNCH_COMMANDS[$LAUNCH_FILE]}
    COMMAND="gnome-terminal -- bash -c \"source ${ROS_SETUP}; source ${PROJECT_DIR}/install/setup.bash; ros2 launch uav_swarms ${LAUNCH_FILE} ${PARAMS}; exec bash\""
    
    # Append the command to the output file
    echo $COMMAND >> $OUTPUT_FILE
done

echo "Commands have been generated and saved to $OUTPUT_FILE"
